﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _2021_6_24
{
    public partial class SignUP : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void affrim_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123456;database=Student_db");
            //con.Open();
            //SqlCommand cmd = new SqlCommand("insert into StudentInfo(stu_name,password,email,intro) values (@userName,@pass,@email,@intro)",con);
            SqlParameter[] pars =
            {
                new SqlParameter("@userName",userName.Text),
                new SqlParameter("@pass",pass.Text),
                new SqlParameter("@email",email.Text),
                new SqlParameter("@intro",intro.Text)
            };
            //cmd.Parameters.AddRange(pars);

            //if (cmd.ExecuteNonQuery() > 0)
            //{
            //    Response.Write("注册成功。<a href='Login.aspx'>去登陆</a>");
            //}
            //else
            //{
            //    Response.Write("注册失败!");    
            //}

            SqlAssistant assistant = new SqlAssistant(serverAddress:".",database:"Student_db");

            if (assistant.Execute("insert into StudentInfo(stu_name,password,email,intro) values (@userName,@pass,@email,@intro)", pars))
            {
                Response.Write("注册成功。<a href='Login.aspx'>去登陆</a>");
            }
            else 
            {
                Response.Write("注册失败!");
            }
        }
    }
}